package jmine.tec.rpc.common.serialization.json;

import jmine.tec.json.JSON;
import jmine.tec.json.JSONString;

/**
 * Conversor de JSON para Java e vice-versa
 * 
 * @author lundberg
 */
public class JSONStringConverter implements JSONConverterStrategy {

    /**
     * {@inheritDoc}
     */
    public boolean matchesJava(Object object) {
        return object instanceof String;
    }

    /**
     * {@inheritDoc}
     */
    public boolean matchesJSON(JSON json) {
        return json instanceof JSONString;
    }

    /**
     * {@inheritDoc}
     */
    public Object toJava(JSONConversionContext context, JSON json) {
        return ((JSONString) json).getString();
    }

    /**
     * {@inheritDoc}
     */
    public JSON toJSON(JSONConversionContext context, Object object) {
        return new JSONString((String) object);
    }
}
